package web

import (
	"061/Sgame/db"
	"061/Sgame/server/game/model/data"
	"061/Sgame/server/login/model"
	"061/Sgame/server/models"
	"061/Sgame/server/web/controller"
	"061/Sgame/server/web/middleware"
	"fmt"
	"github.com/gin-gonic/gin"
)

func Init(router *gin.Engine) {
	//测试数据库，并且初始化数据库
	db.TestDB()
	MigrateTable()
	//还有别的初始化方法
	initRouter(router)
}

func initRouter(router *gin.Engine) {
	router.Use(middleware.Cors())
	router.Any("/account/register", controller.DefaultAccountController.Register)
}
func MigrateTable() {
	err := db.GormDB.AutoMigrate(
		data.Role{}, data.RoleRes{}, model.LoginHistory{}, model.LoginLast{}, models.User{},
		data.RoleAttribute{}, data.MapRoleCity{}, data.MapRoleBuild{}, data.General{}, data.Army{},
		data.WarReport{}, data.Skill{}, data.CityFacility{}, data.CoalitionApply{}, data.Coalition{},
		data.CoalitionLog{},
	)
	if err != nil {
		fmt.Println("迁移表失败。。。", err)
		return
	}
}
